home *** CD-ROM | disk | FTP | other *** search
/ Space & Astronomy / Space and Astronomy (October 1993).iso / mac / VIEWERS / X11 / XLOADIMG.TAR / rle.h < prev    next >
C/C++ Source or Header  |  1991-05-20  |  5KB  |  194 lines

  1.  
  2. /*
  3.  * This software is copyrighted as noted below.  It may be freely copied,
  4.  * modified, and redistributed, provided that the copyright notice is 
  5.  * preserved on all copies.
  6.  * 
  7.  * There is no warranty or other guarantee of fitness for this software,
  8.  * it is provided solely "as is".  Bug reports or fixes may be sent
  9.  * to the author, who may or may not act on them as he desires.
  10.  *
  11.  * You may not include this software in a program or other software product
  12.  * without supplying the source, or without informing the end-user that the 
  13.  * source is available for no extra charge.
  14.  *
  15.  * If you modify this software, you should include a notice giving the
  16.  * name of the person performing the modification, the date of modification,
  17.  * and the reason for such modification.
  18.  */
  19. /* 
  20.  * svfb_global.h - externally visible variables for svfb.
  21.  * 
  22.  * Author:    Todd W. Fuqua
  23.  *         Computer Science Dept.
  24.  *         University of Utah
  25.  * Date:    Sun Jul 29 1984
  26.  * Copyright (c) 1984 Todd W. Fuqua
  27.  * 
  28.  * Added optimised dither square size globals
  29.  * 88/07/13 Graeme W. Gill
  30.  */
  31.  
  32. enum sv_dispatch {
  33.     RUN_DISPATCH
  34. };
  35.  
  36. /* some compilers have problems converting unsigned bytes to float */
  37. #define BYTEBUG
  38.  
  39. /* On BIGENDIAN machines swap the bytes. Everything but vax's and
  40.  * pdp-11's (not sure if it's pdp11 or PDP11 ??)
  41.  * are considered BIGENDIAN machines.
  42.  */
  43.  
  44. #define SWAB(val) (val= memToValLSB((byte *)&val, sizeof(val)))
  45.  
  46. /* fix up some bezerklysims */
  47. #ifndef bzero
  48. # define bzero(xx,yy) memset((char *)(xx),0,(int)(yy))
  49. #endif
  50.  
  51. #ifndef bcopy
  52. # define bcopy(xx,yy,zz) memcpy((char *)(yy),(char *)(xx),(int)(zz))
  53. #endif
  54.  
  55. /* ****************************************************************
  56.  * TAG( rle_pixel rle_map )
  57.  *
  58.  * Typedef for 8-bit (or less) pixel data.
  59.  *
  60.  * Typedef for 16-bit color map data.
  61.  */
  62. typedef unsigned char rle_pixel;
  63. typedef unsigned short rle_map;
  64.  
  65. /*
  66.  * Defines for traditional channel numbers
  67.  */
  68. #define    SV_RED        0        /* red channel traditionally here */
  69. #define SV_GREEN    1        /* green channel traditionally here */
  70. #define    SV_BLUE        2        /* blue channel traditionally here */
  71. #define SV_ALPHA    -1        /* Alpha channel here */
  72.  
  73. /*
  74.  * Return values from rle_get_setup
  75.  */
  76. #define    RLE_SUCCESS    0
  77. #define    RLE_NOT_RLE    -1
  78. #define    RLE_NO_SPACE    -2
  79. #define    RLE_EMPTY    -3
  80. #define    RLE_EOF        -4
  81.  
  82. /*
  83.  * TAG( sv_globals )
  84.  *
  85.  * Definition of "globals" structure used by RLE routines
  86.  */
  87.  
  88. extern struct sv_globals {
  89.     enum sv_dispatch sv_dispatch; /* type of file to create */
  90.     int        sv_ncolors,        /* number of color channels */
  91.       * sv_bg_color,    /* pointer to bg color vector */
  92.         sv_alpha,        /* if !0, save alpha channel */
  93.         sv_background,    /* (background) 0->just save pixels, */
  94.                 /* 1->overlay, 2->clear to bg first */
  95.         sv_xmin,        /* lower X bound (left) */
  96.         sv_xmax,        /* upper X bound (right) */
  97.         sv_ymin,        /* lower Y bound (bottom) */
  98.         sv_ymax,        /* upper Y bound (top) */
  99.         sv_ncmap,        /* number of color channels in color map */
  100.                 /* map only saved if != 0 */
  101.         sv_cmaplen;        /* log2 of color map length */
  102.     rle_map * sv_cmap;    /* pointer to color map array */
  103.     char    ** sv_comments;    /* pointer to array of pointers to comments */
  104.     ZFILE  * svfb_fd;        /* output file */
  105.     /* 
  106.      * Bit map of channels to read/save.  Indexed by (channel mod 256).
  107.      * Alpha channel sets bit 255.
  108.      * 
  109.      * Indexing (0 <= c <= 255):
  110.      *        sv_bits[c/8] & (1 << (c%8))
  111.      */
  112. #define SV_SET_BIT(glob,bit) \
  113.      ((glob).sv_bits[((bit)&0xff)/8] |= (1<<((bit)&0x7)))
  114. #define SV_CLR_BIT(glob,bit) \
  115.     ((glob).sv_bits[((bit)&0xff)/8] &= ~(1<<((bit)&0x7)))
  116. #define SV_BIT(glob,bit) \
  117.     ((glob).sv_bits[((bit)&0xff)/8] & (1<<((bit)&0x7)))
  118.     char    sv_bits[256/8];
  119.     /* 
  120.      * Local storage for rle_getrow & sv_putrow.
  121.      * rle_getrow has
  122.      *        scan_y    int        current Y scanline
  123.      *        vert_skip    int        number of lines to skip
  124.      * sv_putrow has
  125.      *        nblank    int        number of blank lines
  126.      *        brun    short(*)[2] Array of background runs.
  127.      *        fileptr    long        Position in output file.
  128.      */
  129.      union {
  130.     struct {
  131.         int    scan_y,
  132.         vert_skip;
  133.         char is_eof,    /* Set when EOF or EofOp encountered */
  134.         is_seek;    /* If true, can seek input file */
  135.     } get;
  136.     struct {
  137.         int    nblank;
  138.         short (*brun)[2];
  139.         long fileptr;
  140.     } put;
  141.      } sv_private;
  142. } sv_globals;
  143.  
  144.  
  145. /* 
  146.  * buildmap - build a more usable colormap from data in globals struct.
  147.  */
  148. extern rle_pixel **
  149. buildmap();
  150. /* ( globals, minmap, gamma )
  151.  * struct sv_globals * globals;
  152.  * int minmap;
  153.  * double gamma;
  154.  */
  155.  
  156. /*
  157.  * rle_getcom - get a specific comment from the image comments.
  158.  */
  159. extern char *
  160. rle_getcom();
  161. /* ( name, globals )
  162.  * char * name;
  163.  * struct sv_globals * globals;
  164.  */
  165.  
  166. /*
  167.  * rle_putcom - put (or replace) a comment into the image comments.
  168.  */
  169. extern char *
  170. rle_putcom();
  171. /* ( value, globals )
  172.  * char * value;
  173.  * struct sv_globals * globals;
  174.  */
  175.  
  176. /*
  177.  * rle_delcom - delete a specific comment from the image comments.
  178.  */
  179. extern char *
  180. rle_delcom();
  181. /* ( name, globals )
  182.  * char * name;
  183.  * struct sv_globals * globals;
  184.  */
  185.  
  186. /*
  187.  * dither globals
  188.  */
  189.  
  190. extern int dith_levels;    /* target effective number of levels, default = 128 */
  191. extern int dith_np2;    /* set non-zero to use non-power_of_2 matrix size */
  192. extern int dith_size;    /* effective size of the dither matrix chosen */
  193.  
  194.